[AIRFLOW-1560] Add AWS DynamoDB hook and operator for inserting batch items#2560
Closed
sid88in wants to merge 6 commits into
Closed
[AIRFLOW-1560] Add AWS DynamoDB hook and operator for inserting batch items#2560sid88in wants to merge 6 commits into
sid88in wants to merge 6 commits into
Conversation
|
@sid88in, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rfroetscher, @poulainv and @jlowin to be potential reviewers. |
Codecov Report
@@ Coverage Diff @@
## master #2560 +/- ##
==========================================
+ Coverage 70.9% 70.96% +0.06%
==========================================
Files 150 150
Lines 11595 11617 +22
==========================================
+ Hits 8221 8244 +23
+ Misses 3374 3373 -1
Continue to review full report at Codecov.
|
Contributor
Author
|
This is my first PR for airflow. Still getting my head around the build errors :) |
sid88in
force-pushed
the
feature/dynamodb_hooks
branch
from
September 5, 2017 21:55
d07c1d4 to
3a50662
Compare
sid88in
force-pushed
the
feature/dynamodb_hooks
branch
from
September 6, 2017 19:45
7067536 to
3552901
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dear Airflow maintainers,
Please accept this PR. I understand that it will not be reviewed until I have checked off all the steps below!
JIRA
Description
The PR addresses airflow integration with AWS Dynamodb.
Currently there is no hook to interact with DynamoDb for reading or writing items (single or batch insertions). To get started, we want to push data in DynamoDB using airflow jobs (scheduled daily). Idea is to read aggregates from Hive and push in DynamoDB (write data job will run everyday to make this happen). First we want to create DynamoDB hooks (this PR addressed the same) and then create operator to move data from Hive to DynamoDB.
http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html#service-resource
Something to think about - Performance
I think airflow's generic approach for reading all data from source and then transferring to the destination by either storing source data in memory or disk is not the best optimized approach (in cases of big data with potential performance issues). When I started my initial design - I categorized it into 2 use cases a) small data b) big data.. The operators written in airflow code right now mostly handle small data (so does this PR). My approach would be to start with this operator (small data) and then handle big data use case if we see performance issues. I have some thoughts on how we can handle big data operations (using batching mechanism). For instance:
Plan to handle this in subsequent PR.
Something to think about - Other ways of transferring data from hive to dynamodb
There can be multiple ways for this data transfer to occur and here are some of the thoughts on current design decisions (KISS - keep it simple and sweet):
Lambda function : You can write a lambda function to transfer data and trigger the function using AwsLambdaHook ([AIRFLOW-1571] Add AWS Lambda Hook #2570) but lambda lifetime is 5 mins and if the data transfer takes longer lambda will die.
Amazon Ecosystem (Amazon EMR, Big Data Pipeline, AWS Glue): Not to forget adding these systems create additional complexities (aws dependencies, aws limits, system complexities, IAM issues, airflow integrations with additonal dependencies and ofcourse $$)
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBPipeline.html
Tests
test_aws_hook.py
adds mock_dynamodb2 from moto (https://github.com/spulec/moto). Wrote a test case to get aws resource object for dynamodb and create table via resource object and assert if count of items in table is 0 (implies table was created).
test_dynamodb_hook.py
adds mock_dynamodb2 from moto (https://github.com/spulec/moto). Wrote a test case to get aws resource object for dynamodb and create/insert data in dynamodb table. Then this unit test writes 10 items in the table using write_batch_data operation
HiveToDynamoDBTransferTest
this unit test checks the workings of HiveToDynamoDB operator by inserting 1 record in dynamodb table via write operation.
Commits